#!/bin/bash

. $(dirname $(readlink -f $0))/make-weekly-common

WXCRAFTER_BUILD_DIR=${CODELITE_HOME}/build-release-weekly-wxcapp
CODELITE_BUILD_DIR=${CODELITE_HOME}/build-release-weekly

function linux_build_codelite() {
    mkdir -p ${CODELITE_BUILD_DIR}
    cd ${CODELITE_BUILD_DIR}
    rm -fr *.deb
    cmake .. -DCMAKE_BUILD_TYPE=Release -DMAKE_DEB=1 -DCOPY_WX_LIBS=1 -DWITH_CHATAI=ON
    make -j${cpu_count} package
    package_file=`ls -lt *.deb|awk '{print $9;}'|head -n 1`
    upload_path="/var/www/html/downloads/codelite/${version}"
    ssh root@codelite.org "mkdir -p ${upload_path}"
    scp ${package_file} root@codelite.org:${upload_path}
    ssh root@codelite.org \
        "cd ${upload_path} && sha256sum ${package_file} |cut -d' ' -f1 > ${package_file}.sha1 && cat ${package_file}.sha1"
    cd $curdir
}

function linux_build_wxcrafter() {
    mkdir -p ${WXCRAFTER_BUILD_DIR}
    cd ${WXCRAFTER_BUILD_DIR}
    rm -fr *.deb
    cmake .. -DCMAKE_BUILD_TYPE=Release -DCOPY_WX_LIBS=1 -DWXC_APP=1 -Wno-dev 
    make -j${cpu_count} package
    rm -f *Unspecified.deb
    package_file=`ls -lt *.deb|awk '{print $9;}'|head -n 1`
    upload_path="/var/www/html/downloads/wxcrafter/${version}"
    ssh root@codelite.org "mkdir -p ${upload_path}"
    scp ${package_file} root@codelite.org:${upload_path}
    ssh root@codelite.org \
        "cd ${upload_path} && sha256sum ${package_file} |cut -d' ' -f1 > ${package_file}.sha1 && cat ${package_file}.sha1"
    cd $curdir
}

linux_build_codelite

if [[ "${BUILD_WXC}" == "YES" ]]; then
    linux_build_wxcrafter
fi

